package cn.mastor.org.controller;

import cn.mastor.basic.util.PageList;
import cn.mastor.org.domain.Sdictionarydetail;
import cn.mastor.org.domain.Systemdictionarytype;
import cn.mastor.org.query.SdictionarydetailQuery;
import cn.mastor.org.query.SystemdictionarytypeQuery;
import cn.mastor.org.service.ISdictionarydetailService;
import cn.mastor.org.service.ISystemdictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RequestMapping("/dictype")
@RestController
public class SystemdictionarytypeController {
    @Autowired
    private ISdictionarydetailService iservice;
    @Autowired
    private ISystemdictionarytypeService service;
    @GetMapping()
    public List findAll() {
        System.out.println(service.findAll());
        return  service.findAll();
    }
    @PostMapping
    public PageList<Systemdictionarytype> findbyPage(@RequestBody SystemdictionarytypeQuery query){
        return service.queryByPage(query);
    }
    @PutMapping
    public void addOrUpdate(@RequestBody Systemdictionarytype systemdictionarytype){
        if (null == systemdictionarytype.getId()){
            // 添加
            service.add(systemdictionarytype);
        }else {
            // 修改
            service.update(systemdictionarytype);
        }
    }
    @DeleteMapping("/{id}")
    public void delete(@PathVariable("id") Long id){
        iservice.deleteby(id);
        service.delete(id);
    }
    @PatchMapping()
    public void patchdel(@RequestBody List<Long> ids) {
        service.batchDel(ids);
    }
}
